<?php

namespace Wechat\Controller;

class SpecialProductController extends CommonController {


    public function index() {
        if(!check_role($this->customer["customer_id"], "1,2,3,7,8,10,11,12")){
            $this->error("您没有访问权限！");
            exit();
        }
        $this->assign("access", check_role($this->customer["customer_id"], "1,2,3,7,8,10,11,12"));
//        $this->assign("supplier",$_REQUEST["supplier"]);

        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user",$user);
        $this->display("index");
    }
    
    public function SpecialProductList() {

        $classId = I("post.classId");
        $keyword = I("post.keyword");
//        $supplier = I("post.supplier");

        if(!isNullOrEmpty($classId)) {
            $map["sp.class_id"] = $classId;
        }
        if(!isNullOrEmpty($keyword)) {
            $map["sp.name"] = array('like','%'.$keyword.'%');
        }
//        if(!isNullOrEmpty($supplier)) {
//            $map["sl.supplier_name"] = $supplier;
//        }
        $employee = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $map["sp.enterprise_code"] = $employee["enterprise_code"];
        $list = D("SpecialProduct")->alias("sp")
            ->join("left join __CLASS__ cl on cl.class_id = sp.class_id")
//            ->join("left join __SUPPLIER__ sl on sl.supplier_id = sp.supplier_id")
            ->order("sp.count desc")
            ->where($map)
            ->field("sp.*,cl.class_name")
            ->select();

        echo json_encode($list);

    }

    public function specialOrder() {
        if(!check_role($this->customer["customer_id"], "1,2,3,7,8,10,11,12,14")){
            $this->error("您没有访问权限！");
            exit();
        }
        $id = $_REQUEST["id"];
        $specialProduct = D("SpecialProduct")->queryById($id);
//        if(isNullOrEmpty($specialProduct)) {
//            $this->redirect(U("product/index"));
//        }
        $class = D("Class")->queryById($specialProduct["class_id"]);
        $map["special_product_id"] = $id;
        $agentList = D('Agent')
            ->where($map)
            ->select();
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $agentId = $user["agent_id"];
        $role = explode(',',$user["role"]);
        if (in_role($role,"12")) {
            $prosthetist = $user;
        }else{
            $prosthetist = D("admin")->where(array('employee_id'=>965))->find();
        }

        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user", $user);
        $this->assign("prosthetist", $prosthetist);
        $this->assign("specialProduct", $specialProduct);
        $this->assign("class", $class);
        $this->assign("agentList", $agentList);
        $this->assign("agentId", $agentId);
        $trimProductAgent = str_replace('1,', '', $specialProduct["agent_id"]);
        if(sizeof(explode(',',$trimProductAgent)) == 1){
            $defaultAgent = D("Agent")->where(array('agent_id'=>$trimProductAgent))->find();
            $this->assign("defaultAgent", $defaultAgent);
        }
        if(sizeof(explode(',',$agentId)) == 1){
            $defaultAgent = D("Agent")->where(array('agent_id'=>$agentId))->find();
            $this->assign("defaultAgent", $defaultAgent);
        }

        $this->display("specialOrder");

    }

    public function createOrder() {

        $lastOrder = D("SpecialOrder")->alias("so")
            ->order("so.special_order_id desc")
            ->limit(1)
            ->select();
//        echo($lastOrder[0]["special_order_no"]);

        $specialProductId = $_REQUEST["specialProductId"];
        $specialProduct = D("SpecialProduct")->queryById($specialProductId);
        $data["code"] = 200;

        if(isNullOrEmpty($specialProduct)) {
            $data["code"] = -1;
            $data["msg"] = "商品不存在";
            echo json_encode($data);
            exit();
        }

        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $specialOrderData["special_order_no"] = "STS".date('Ymd',time()) . sprintf("%03d", substr(D("SpecialOrder")->count(), -3, 3)+1);
        $specialOrderData["create_time"] = getCurrentDate();
        $specialOrderData["special_product_id"] = $specialProductId;
        $specialOrderData["sale_price"] = I("post.salePrice");
//        $specialOrderData["size"] = I("post.size");
        $sizeNumList = explode('/',I("post.size"));
        $sizeNameList = explode('/',$specialProduct["size"]);
        $specialOrderData["size"] = "";
        for($i=0; $i< count($sizeNumList); $i++){
            if($sizeNumList[$i] > 0){
                if(!isNullOrEmpty($specialOrderData["size"])){
                    $specialOrderData["size"] .= ", ";
                }
                $specialOrderData["size"] .= "[". $sizeNameList[$i] ."]x" .$sizeNumList[$i];
            }
        }

        $specialOrderData["number"] = I("post.number");
//        $specialOrderData["delivery_type"] = I("post.deliveryType");
//        $specialOrderData["receive_name"] = I("post.receiveName");
//        $specialOrderData["receive_address"] = I("post.receiveAddress");
//        $specialOrderData["receive_contact"] = I("post.receiveContact");
        $specialOrderData["room"] = I("post.room");
        $specialOrderData["doctor_name"] = I("post.doctorName");
        $specialOrderData["patient_name"] = I("post.patientName");
        $specialOrderData["patient_id"] = I("post.patientId");
        $specialOrderData["prosthetist_id"] = I("post.prosthetistId");
        $specialOrderData["prosthetist_name"] = I("post.prosthetistName");
        $specialOrderData["prepayment"] = I("post.prepayment");
        $specialOrderData["product_type"] = I("post.productType");
        $specialOrderData["payment_type"] = I("post.paymentType");
        $specialOrderData["note"] = I("post.note");
        $specialOrderData["need_invoice"] = I("post.needInvoice");
        $specialOrderData["invoice_name"] = I("post.invoiceName");
        $specialOrderData["invoice_number"] = I("post.invoiceNumber");
        $specialOrderData["invoice_detail"] = I("post.invoiceDetail");
        $specialOrderData["agent_name"] = I("post.agentName");
        $specialOrderData["total_price"] = $specialOrderData["sale_price"]*$specialOrderData["number"];
        $specialOrderData["employee_id"] = $user["employee_id"];
        if(I("post.needApproval") == 1){
            $specialOrderData["status"] = -4;
        }else{
            $specialOrderData["status"] = -1;
        }
        $specialOrderData["enterprise_code"] = $user["enterprise_code"];
        $nameArr =array();
        array_push($nameArr, "special_product_id");
        array_push($nameArr, "sale_price");
        array_push($nameArr, "number");
        array_push($nameArr, "delivery_type");
        array_push($nameArr, "receive_name");
        array_push($nameArr, "receive_address");
        array_push($nameArr, "receive_contact");
        array_push($nameArr, "room");
        array_push($nameArr, "doctor_name");
        array_push($nameArr, "patient_name");
        array_push($nameArr, "patient_id");
        array_push($nameArr, "prosthetist_id");
        array_push($nameArr, "prepayment");
        array_push($nameArr, "product_type");
        array_push($nameArr, "note");
        array_push($nameArr, "invoice_name");
        array_push($nameArr, "invoice_number");
        array_push($nameArr, "invoice_detail");
        array_push($nameArr, "agent_name");
        array_push($nameArr, "patient_name");
        array_push($nameArr, "total_price");
        array_push($nameArr, "employee_id");

        $theSame = 1;
        foreach ($nameArr as $name) {
            if($specialOrderData[$name] != $lastOrder[0][$name]){
                $theSame = -1;
            }
        }

        $minute=floor((strtotime(getCurrentDate())-strtotime($lastOrder[0]["create_time"]))%86400/60);

        if($minute < 2){
            $data["msg"] = $minute;
        }else{
            $theSame = -1;
        }

        if($theSame == 1){
            $data["code"] = -1;
            $data["msg"] .= "订单重复";
            echo json_encode($data);
            exit();
        }

        if(I("post.paymentType") == "微信现结" && I("post.needPay") == "1"){
            $specialOrderData["status"] = -5;
            $payId = D('Pay')->add(array(
                'out_trade_no' => "PAID".date('Ymd',time()) . sprintf("%03d", substr(D("Pay")->count(), -3, 3)+1),
                'money' => $specialOrderData["total_price"],
                'status' => 0,
                'type' => 3,
                'callback' => "",
                'create_time' => getCurrentDate(),
                'update_time' => getCurrentDate(),
                'pay_source' => 1
            ));

            $specialOrderData["pay_id"] = $payId;
            $data["special_order_no"] = $specialOrderData["special_order_no"];

            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/specialProduct/orderList/?id=". $specialOrderData["special_order_id"]."&status=-5";
            $notifyData["first"] = "您已下订单，请支付";
            $notifyData["keyword1"] = $specialProduct["name"]."共 ".$specialOrderData["number"]." 件";
            $notifyData["keyword2"] = $specialOrderData["special_order_no"];
            $notifyData["keyword3"] = $specialOrderData["total_price"]." 元";
            $notifyData["remark"] = "点击查看订单详情。";

            $notifyData["openid"] = $this->customer["openid"];
            OrderUnpaidNotify($notifyData);
        }

        $specialOrderId = D("SpecialOrder")->add($specialOrderData);
        $specialProduct["count"] += $specialOrderData["number"];
        D("SpecialProduct")->updateInfo($specialProduct);
//        $data["special_order_id"] = $specialOrderId;

        //推送信息到西钓客服
        if($specialOrderData["status"] == -1){
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/specialProduct/orderList/?id=". $specialOrderId;
            $notifyData["first"] = "收到医院定制订单。";
            if(!isNullOrEmpty($specialOrderData["patient_name"])){
                $notifyData["first"] .= "患者：" . $specialOrderData["patient_name"] . "，ID：" . $specialOrderData["patient_id"]. "，科室：" . $specialOrderData["room"]. "，医生：" . $specialOrderData["doctor_name"];
            }
            $notifyData["keyword1"] = $specialOrderData["special_order_no"];
            $notifyData["keyword2"] = $specialProduct["name"] . "共 " . $specialOrderData["number"] . " 件 [" . $specialOrderData["agent_name"] . "]";
            $notifyData["keyword3"] = $specialOrderData["create_time"];
            $notifyData["keyword4"] = $specialOrderData["total_price"];
            if($specialOrderData["payment_type"] == "预付"){
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"]."￥".$specialOrderData["prepayment"] .")";
            }else{
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"].")";
            }
            $notifyData["keyword5"] = "支具师：" . $specialOrderData["prosthetist_name"] . "，下单人：" . $user["admin_name"];

            $notifyData["remark"] =  $specialOrderData["note"];

//            $adminRoleArr = array("1","8","10");
//            $openidArray = getNotifyArr($adminRoleArr, $user["enterprise_code"]);
            $openidArray = getNotifyArrByName("createSpecialOrder", $user["enterprise_code"]);
            array_push($openidArray, $user["openid"]);
            $openidArray = array_unique($openidArray);
            foreach ($openidArray as $openid) {
                $notifyData["openid"] = $openid;
                finishedOrderNotify($notifyData);
            }
        }
        if($specialOrderData["status"] == -4){
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/specialProduct/orderList/?id=". $specialOrderId;
            $notifyData["first"] = "收到待审批医院定制订单 [" . $specialOrderData["special_order_no"] ."]";
            $notifyData["keyword1"] = $user["admin_name"];
            $notifyData["keyword2"] = $specialProduct["name"]."共 ".$specialOrderData["number"]." 件，总价：". $specialOrderData["total_price"] ."元";
            $notifyData["keyword3"] = "下单价：" . $specialOrderData["sale_price"] ." 元，原价：" . $specialProduct["price"] ." 元，(".$specialOrderData["payment_type"].")";
            $notifyData["remark"] = "请审批人点击详情进行审核。";
            if(!isNullOrEmpty($specialOrderData["note"])){
                $notifyData["remark"] .= " 备注：" . $specialOrderData["note"];
            }

//            $adminRoleArr = array("1");
//            $openidArray = getNotifyArr($adminRoleArr, $user["enterprise_code"]);
            $openidArray = getNotifyArrByName("auditFinishedOrder", $user["enterprise_code"]);
            $openidArray = array_unique($openidArray);
            foreach ($openidArray as $openid) {
                $notifyData["openid"] = $openid;
                ApplyApprovalNotify($notifyData);
            }

            $notifyData["openid"] = $user["openid"];
            $notifyData["first"] = "医院定制订单 [" . $specialOrderData["special_order_no"]."] 待审批";
            $notifyData["remark"] = "请等待审批人审批。";
            if(!isNullOrEmpty($specialOrderData["note"])){
                $notifyData["remark"] .= " 备注：" . $specialOrderData["note"];
            }
            ApplyApprovalNotify($notifyData);
        }

        $data["code"] = 200;
        echo json_encode($data);

    }

    public function orderList() {
        $id = $_REQUEST["id"];
        $orderStatus = $_REQUEST["status"];
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user", $user);
        $this->assign("orderId", $id);
        $this->assign("orderStatus", $orderStatus);
        $this->display("orderList");
    }

    public function myOrderList() {
        $map["so.status"] = array('neq','-3');
        $status = I("post.status");
        if(!isNullOrEmpty($status)) {
            $map["so.status"] = $status;
        }
        if(!check_role($this->customer["customer_id"], "0,1,3,7,8,10,12")){
            $map["so.employee_id"] = $this->customer["customer_id"];
        }
        $orderId = I("post.orderId");
        if(!isNullOrEmpty($orderId) && I("post.ignoreOrderId") != '1') {
            $map["special_order_id"] = $orderId;
        }
        $employee = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $map["so.enterprise_code"] = $employee["enterprise_code"];
        $list = D("SpecialOrder")->alias("so")
            ->join("left join __SPECIAL_PRODUCT__ sp on sp.special_product_id = so.special_product_id")
            ->join("left join __ADMIN__ e on e.employee_id = so.employee_id")
            ->join("left join __ADMIN__ ad on ad.employee_id = so.delivery_id")
            ->join("left join __ADMIN__ pv on pv.employee_id = so.approve_id")
            ->where($map)
            ->order("so.special_order_id desc")
            ->field("so.*,sp.price as single_price,sp.image_url,sp.name as special_product_name, e.admin_name, ad.admin_name as delivery_name, pv.admin_name as approve_name")
            ->select();

        echo json_encode($list);
    }
    
    public function orderCart() {
        $orderStatus = $_REQUEST["status"];
        $this->assign("orderStatus", $orderStatus);
        $this->display("orderCart");
    }

    public function myOrderCart() {
        $map["so.status"] = "-3";
        $map["so.employee_id"] = $this->customer["customer_id"];
        $list = D("SpecialOrder")->alias("so")
            ->join("left join __SPECIAL_PRODUCT__ sp on sp.special_product_id = so.special_product_id")
            ->join("left join __ADMIN__ e on e.employee_id = so.employee_id")
            ->join("left join __ADMIN__ ad on ad.employee_id = so.delivery_id")
            ->where($map)
            ->order("so.special_order_id desc")
            ->field("so.*,sp.price as single_price,sp.image_url,sp.name as special_product_name, e.admin_name, ad.admin_name as delivery_name")
            ->select();

        echo json_encode($list);
    }

    public function addCart() {

        $specialProductId = $_REQUEST["specialProductId"];
        $specialProduct = D("SpecialProduct")->queryById($specialProductId);
        $data["code"] = 200;

        if(isNullOrEmpty($specialProduct)) {
            $data["code"] = -1;
            $data["msg"] = "商品不存在";
            echo json_encode($data);
            exit();
        }

        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $specialOrderData["special_order_no"] = "STS".date('Ymd',time()) . sprintf("%03d", substr(D("SpecialOrder")->count(), -3, 3)+1);
        $specialOrderData["create_time"] = getCurrentDate();
        $specialOrderData["special_product_id"] = $specialProductId;
        $specialOrderData["sale_price"] = I("post.salePrice");
        $sizeNumList = explode('/',I("post.size"));
        $sizeNameList = explode('/',$specialProduct["size"]);
        $specialOrderData["size"] = "";
        for($i=0; $i< count($sizeNumList); $i++){
            if($sizeNumList[$i] > 0){
                if(!isNullOrEmpty($specialOrderData["size"])){
                    $specialOrderData["size"] .= ", ";
                }
                $specialOrderData["size"] .= "[". $sizeNameList[$i] ."]x" .$sizeNumList[$i];
            }
        }

        $specialOrderData["number"] = I("post.number");
        $specialOrderData["agent_name"] = I("post.agentName");
        $specialOrderData["total_price"] = $specialOrderData["sale_price"]*$specialOrderData["number"];
        $specialOrderData["employee_id"] = $user["employee_id"];
        $specialOrderData["status"] = -3;
        $specialOrderData["enterprise_code"] = $user["enterprise_code"];

        $specialOrderId = D("SpecialOrder")->add($specialOrderData);
        $specialProduct["count"] += $specialOrderData["number"];
        D("SpecialProduct")->updateInfo($specialProduct);
        $data["code"] = 200;
        echo json_encode($data);

    }

    public function removeOrder() {

        $id = $_REQUEST['id'];
        D("SpecialOrder")->deleteById($id);

        $this->display("orderCart");
    }

    public function submitCart() {
        $map["so.status"] = "-3";
        $map["so.employee_id"] = $this->customer["customer_id"];
        $cartList = D("SpecialOrder")->alias("so")
            ->join("left join __SPECIAL_PRODUCT__ sp on sp.special_product_id = so.special_product_id")
            ->where($map)
            ->field("so.*,sp.name as special_product_name")
            ->select();

        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        foreach ($cartList as $specialOrderData) {
            $specialOrderData["create_time"] = getCurrentDate();
//            $specialOrderData["delivery_type"] = I("post.deliveryType");
//            $specialOrderData["receive_name"] = I("post.receiveName");
//            $specialOrderData["receive_address"] = I("post.receiveAddress");
//            $specialOrderData["receive_contact"] = I("post.receiveContact");
            $specialOrderData["room"] = I("post.room");
            $specialOrderData["doctor_name"] = I("post.doctorName");
            $specialOrderData["patient_name"] = I("post.patientName");
            $specialOrderData["patient_id"] = I("post.patientId");
            $specialOrderData["prosthetist_id"] = I("post.prosthetistId");
            $specialOrderData["prosthetist_name"] = I("post.prosthetistName");
            $specialOrderData["prepayment"] = I("post.prepayment");
            $specialOrderData["product_type"] = I("post.productType");
            $specialOrderData["payment_type"] = I("post.paymentType");
            $specialOrderData["note"] = I("post.note");
            $specialOrderData["need_invoice"] = I("post.needInvoice");
            $specialOrderData["invoice_name"] = I("post.invoiceName");
            $specialOrderData["invoice_number"] = I("post.invoiceNumber");
            $specialOrderData["invoice_detail"] = I("post.invoiceDetail");
            $specialOrderData["status"] = -1;
            D("SpecialOrder")->updateInfo($specialOrderData);

            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/specialProduct/orderList/?id=". $specialOrderData["special_order_id"];
            $notifyData["first"] = "收到医院定制订单。";
            if(!isNullOrEmpty($specialOrderData["patient_name"])){
                $notifyData["first"] .= "患者：" . $specialOrderData["patient_name"] . "，ID：" . $specialOrderData["patient_id"]. "，科室：" . $specialOrderData["room"]. "，医生：" . $specialOrderData["doctor_name"];
            }
            $notifyData["keyword1"] = $specialOrderData["special_order_no"];
            $notifyData["keyword2"] = $specialOrderData["special_product_name"] . "共 " . $specialOrderData["number"] . " 件 [" . $specialOrderData["agent_name"] . "]";
            $notifyData["keyword3"] = $specialOrderData["create_time"];
            $notifyData["keyword4"] = $specialOrderData["total_price"];
            if($specialOrderData["payment_type"] == "预付"){
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"]."￥".$specialOrderData["prepayment"] .")";
            }else{
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"].")";
            }
            $notifyData["keyword5"] = "支具师：" . $specialOrderData["prosthetist_name"] . "，下单人：" . $user["admin_name"];

            $notifyData["remark"] =  $specialOrderData["note"];

//            $adminRoleArr = array("1","8","10");
//            $openidArray = getNotifyArr($adminRoleArr, $user["enterprise_code"]);
            $openidArray = getNotifyArrByName("createSpecialOrder", $user["enterprise_code"]);
            array_push($openidArray, $user["openid"]);
            $openidArray = array_unique($openidArray);
            foreach ($openidArray as $openid) {
                $notifyData["openid"] = $openid;
                finishedOrderNotify($notifyData);
            }
        }
        echo json_encode($data);

    }

    public function approve($orderId, $status) {
        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();

        $specialOrderData = D("SpecialOrder")->queryById($orderId);
        if($specialOrderData["status"] != -4){
            $data["message"] = "工单已审批过，无需重复审批。";
            echo json_encode($data);
            return;
        }
        $specialOrderData["status"] = $status;
        $specialOrderData["approve_id"] = $user["employee_id"];
        $specialOrderData["approve_time"] = getCurrentDate();
        D("SpecialOrder")->updateInfo($specialOrderData);
        $specialProduct = D("SpecialProduct")->queryById($specialOrderData["special_product_id"]);
        $sales = D("admin")->where(array('employee_id'=>$specialOrderData["employee_id"]))->find();
        if($status == -1) {
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/specialProduct/orderList/?id=" . $specialOrderData["special_order_id"];
            $notifyData["first"] = "收到医院定制订单。";
            if(!isNullOrEmpty($specialOrderData["patient_name"])){
                $notifyData["first"] .= "患者：" . $specialOrderData["patient_name"] . "，ID：" . $specialOrderData["patient_id"]. "，科室：" . $specialOrderData["room"]. "，医生：" . $specialOrderData["doctor_name"];
            }
            $notifyData["keyword1"] = $specialOrderData["special_order_no"];
            $notifyData["keyword2"] = $specialProduct["name"] . "共 " . $specialOrderData["number"] . " 件 [" . $specialOrderData["agent_name"] . "]";
            $notifyData["keyword3"] = $specialOrderData["create_time"];
            $notifyData["keyword4"] = $specialOrderData["total_price"];
            if($specialOrderData["payment_type"] == "预付"){
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"]."￥".$specialOrderData["prepayment"] .")";
            }else{
                $notifyData["keyword4"] .=  " (".$specialOrderData["payment_type"].")";
            }
            $notifyData["keyword5"] = "支具师：" . $specialOrderData["prosthetist_name"] . "，下单人：" . $user["admin_name"];

            $notifyData["remark"] =  $specialOrderData["note"];

//            $adminRoleArr = array("1", "8", "10");
//            $openidArray = getNotifyArr($adminRoleArr, $user["enterprise_code"]);
            $openidArray = getNotifyArrByName("createSpecialOrder", $user["enterprise_code"]);
//            array_push($openidArray, $user["openid"]);
            $openidArray = array_unique($openidArray);
            foreach ($openidArray as $openid) {
                $notifyData["openid"] = $openid;
                finishedOrderNotify($notifyData);
            }
            $notifyData["first"] = "医院定制订单 [" . $specialOrderData["special_order_no"] ."] 审批通过。";
            $notifyData["keyword2"] = "审批通过";
        }else{
            $notifyData["first"] = "医院定制订单 [" . $specialOrderData["special_order_no"] ."] 审批未通过。";
            $notifyData["keyword2"] = "审批未通过";
        }

        $notifyData["keyword1"] = $specialProduct["name"]."共 ".$specialOrderData["number"]." 件，总价：". $specialOrderData["total_price"] ."元";
        $notifyData["keyword3"] = "审批人：" . $user["admin_name"] . "，下单人：" . $sales["admin_name"];
        $notifyData["keyword4"] = getCurrentDate();
        $notifyData["remark"] = null;
        $notifyData["url"] = null;
        $openidArray = array($user["openid"],$sales["openid"]);
        $openidArray = array_unique($openidArray);
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            ApprovalResultNotify($notifyData);
        }
//        $data["message"] = $specialOrderData["status"];
        echo json_encode($data);
    }
}